{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 14,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                     transaction\n",
      "timestamp                       \n",
      "2020-01-01 01:00:00       100.00\n",
      "2020-01-01 05:00:00       102.00\n",
      "2020-01-02 03:00:00       103.00\n",
      "2020-01-04 04:00:00       102.80\n",
      "2020-01-05 00:00:00        99.88\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "# Transactions do not have regular intervals and may miss days\n",
    "data = {\n",
    "    \"timestamp\": [\n",
    "        pd.Timestamp(\"2020-01-01 01:00\"),\n",
    "        pd.Timestamp(\"2020-01-01 05:00\"),\n",
    "        pd.Timestamp(\"2020-01-02 03:00\"),\n",
    "        pd.Timestamp(\"2020-01-04 04:00\"),\n",
    "        pd.Timestamp(\"2020-01-05 00:00\"),\n",
    "    ],\n",
    "    \"transaction\": [\n",
    "        100.00,\n",
    "        102.00,\n",
    "        103.00,\n",
    "        102.80,\n",
    "        99.88\n",
    "    ]\n",
    "}\n",
    "\n",
    "\n",
    "df = pd.DataFrame.from_dict(data, orient=\"columns\")\n",
    "df.set_index(\"timestamp\", inplace=True)\n",
    "\n",
    "print(df)"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "              open    high     low   close\n",
      "timestamp                                 \n",
      "2020-01-01  100.00  102.00  100.00  102.00\n",
      "2020-01-02  103.00  103.00  103.00  103.00\n",
      "2020-01-03     NaN     NaN     NaN     NaN\n",
      "2020-01-04  102.80  102.80  102.80  102.80\n",
      "2020-01-05   99.88   99.88   99.88   99.88\n"
     ]
    }
   ],
   "source": [
    "# https://stackoverflow.com/a/36223274/315168\n",
    "naive_resample = df[\"transaction\"].resample(\"1D\") .agg({'open': 'first', 'high': 'max', 'low': 'min', 'close': 'last'})\n",
    "print(naive_resample)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
